package com.liu.xml;

import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author liubo
 */
public class ParseBySax {
    public String xmlPath = "";

    public ParseBySax(String xmlPath){
        this.xmlPath = xmlPath;
    }

    public void read() {
        SAXParserFactory sax = SAXParserFactory.newInstance();
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(xmlPath);
        try {
            SAXParser parser = sax.newSAXParser();
            parser.parse(is,new SaxXml());
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
